<template>
    <div class="aui-info">
        <div class="img-box">
            <img src="" id="img-txz" class="aui-img-round user-img"/>
        </div>      
        <input type="file" accept="image/*" id="file-txz" name="file" class="fileInput"  value="" @change="userImg"/>
        <div class="user-name">
            <router-link to='/login'>登陆 / </router-link>
            <router-link to='/register'>注册</router-link>
        </div>
        
   </div>
</template>

<script>
export default {
    name: "HeadPortrait",
    
    methods: {
        // 实现上传图片后将图片显示在图片盒子内
        userImg() {
            var img = document.getElementById('img-txz');
            var url = null;
            var fileObj = document.getElementById('file-txz').files[0];
            if (window.createObjcectURL != undefined) {
                url = window.createOjcectURL(fileObj);
            } else if (window.URL != undefined) {
                url = window.URL.createObjectURL(fileObj);
            } else if (window.webkitURL != undefined) {
                url = window.webkitURL.createObjectURL(fileObj);
            }
            img.src = url;
        }
    }
}
</script>

<style scoped>
    .img-box {
        height: 50px;
        width: 50px;
        border-radius: 50%;
        background-color: #999999;
        overflow: hidden;
        margin-left: 20px;
    }
    .fileInput{
        position: absolute;
        top: 80px;
        bottom: 0;
        left: 10px;
        right: 0;
        opacity: 0;
        display: block;
        width: 50px;
        height: 50px;
        clear: both;
    }
    .aui-info {
        margin-top: 30px;
        height: 50px;
        padding: 10px 0;
    }  
    .user-name {
        font-size: 20px;
        height: 50px;
        line-height: 50px;
        margin-left: 20px;
    }  
    .user-name a {
        color: #f54500;
    }
    .aui-info {
        display: flex;
    }
    #img-txz {
        width: 50px;
    }
</style>